<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="crm.util.ParamUtil"%>
<%@page import="java.util.*"%>
<%@page import="crm.control.RecepitControl"%>
<%@page import="java.util.Collection"%>
<%@page import="crm.model.Recepit"%>
<%@page import="crm.control.LinkmanControl"%>
<%@page import="crm.control.CustomerControl"%>
<%@page import="crm.util.GetBaseParam"%>
<%@page import="crm.control.EmployeesControl"%>
<%@page import="crm.model.Employees"%>
<%@page import="crm.control.RecepitDescriptionControl"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>天成科技CRM管理系统</title>
<!--                       CSS                       -->
<!-- Reset Stylesheet -->
<link rel="stylesheet" href="../../../resources/css/reset.css" type="text/css" media="screen" />
<!-- Main Stylesheet -->
<link rel="stylesheet" href="../../../resources/css/style.css" type="text/css" media="screen" />
<!-- Invalid Stylesheet. This makes stuff look pretty. Remove it if you want the CSS completely valid -->
<link rel="stylesheet" href="../../../resources/css/invalid.css" type="text/css" media="screen" />
<!--                       Javascripts                       -->
<!-- jQuery -->
<script type="text/javascript" src="../../../resources/scripts/jquery-1.3.2.min.js"></script>
<!-- jQuery Configuration -->
<script type="text/javascript" src="../../../resources/scripts/simpla.jquery.configuration.js"></script>
 <script type="text/javascript" src="../../../resources/js/WebCalendar.js"></script>
<!-- Facebox jQuery Plugin -->
<script type="text/javascript" src="../../../resources/scripts/facebox.js"></script>
<!-- jQuery WYSIWYG Plugin -->
<script type="text/javascript" src="../../../resources/scripts/jquery.wysiwyg.js"></script>
<!-- jQuery Datepicker Plugin -->
<script type="text/javascript" src="../../../resources/scripts/jquery.datePicker.js"></script>
<script type="text/javascript" src="../../../resources/scripts/jquery.date.js"></script>
<script type="text/javascript" src="../../../resources/js/reinitIframe.js"></script>
<script type='text/javascript'>
$(function(){
	var num=document.getElementById('num').value;
	setInterval(function(){
		new ReinitIframe('iadd');
		new ReinitIframe('iinformation');
		for(var i=1;i<=num;i++){
			var check = 'icheck' + i;
			new ReinitIframe(check);
		}
	},200);
	for(var i = 1;i<num + 1;i++){
		var tid = "time" + i;
		var tem = document.getElementById(tid);
		if(tem.value != "null"){
			var exp = /(\d{4})-(\d{1,2})-(\d{1,2})/;
			var re = exp.exec(tem.value);
			var d1 = new Date();
			d1.setFullYear(re[1]);
			d1.setMonth(re[2]-1);
			d1.setDate(re[3]);
			d1.setHours(0);
			d1.setMinutes(0);
			d1.setSeconds(0);
			var d1m = Date.UTC(d1.getFullYear(),d1.getMonth(),d1.getDate(),d1.getHours(),d1.getMinutes(),d1.getSeconds());
			var d2 = new Date();
			var d2m = d2.valueOf();
			var t = d2m - d1m;
			if(d2m - d1m > 259200000){
				tem.parentNode.parentNode.style.background = "#FCA3AB";
			}
		}
	}
	new SortTr('tbcontent','predicttime','predictbtn');
	new SrotStage('tbcontent','money','money');
	new SrotStage('tbcontent','stage','stage');
})
</script>
<style type="text/css">
.hide{
    position: absolute;
    zoom: 0.001;
    -moz-transform: scale(0);
    -webkit-transform: scale(0);
    -o-transform: scale(0);
    transform: scale(0);
}
</style>
</head>
<body>
<%
       request.setCharacterEncoding("utf-8");
       Employees cu = (Employees)session.getAttribute("user");
       int  userType  = ParamUtil.getInt(request,"userType",cu.getPosition());  //判断访问当前页面用户类型
       //跟单查询（阶段，当前跟单人，创建人，客户名称，联系人，创建时间）
       String stage="";
       String person="";
       String creator="";
       String customer="";
       String sort="";
       String creat_time="";
       String title ="";
       
       int type=ParamUtil.getInt(request,"type",1);
       //System.out.print(type);
       if(type==1){
            stage = ParamUtil.getString(request,"stage",null);
            person = ParamUtil.getString(request,"person",null);
            creator = ParamUtil.getString(request,"creator",null);
            sort=ParamUtil.getString(request,"sort",null);
            customer=ParamUtil.getString(request,"customer",null);
            creat_time=ParamUtil.getString(request,"creat_time",null);
            title = ParamUtil.getString(request,"title",null);
            
            session.setAttribute("stage",stage);//与获取专业中session保持一致
            session.setAttribute("person",person);
            session.setAttribute("creator",creator);
            session.setAttribute("sort",sort);
            session.setAttribute("customer",customer);
            session.setAttribute("creat_time",creat_time);
       
        }
        else{
        	stage = (String)session.getAttribute("stage");
        	person = (String)session.getAttribute("person");
        	creator = (String) session.getAttribute("creator");
        	sort = (String)session.getAttribute("sort");
        	customer = (String)session.getAttribute("customer");
        	creat_time = (String)session.getAttribute("creat_time");
            
        }
       
       //session.setAttribute("name",name);
       //session.setAttribute("stunum",stunum);
 %>
<%
if(cu.getPosition()!=1){
%>
	<script type='text/javascript'>
	$(function(){
		$('#flag').val('1');
		setInterval(function(){
				$.ajax({
					url: "../../control/statistics/alert.jsp",
					cache: false,
					contentType: "application/x-www-form-urlencoded; charset=UTF-8",
					dataType: "text",
					success:function(data){
						data = data.replace(/\s+/g,'');				
						var reg = /^true/gi;	
						var arr = [];
						if($('#flag').val() == 1){
							if(reg.test(data+'')){
								$(".promot").show();
								data = data.replace(reg,'');
								arr = data.split(/\?/);
								var ect='';
								if(arr.length>10){
									arr = arr.slice(0,10);
									ect = '等'
								}
								if($('bgsound').size()==0)
								$('body').append("<bgsound src='../../../resources/css/images/msg.wav'/>");
								var restring = arr.join("、");
								restring = restring.replace(/\、$/,'');
								restring += ect;
								$('.reply').html(restring);
							} else{
								$('.promot').hide();
							}
						} else{
							return;
						}				
						
					}
				})
		},5000);
		$('#close').click(function(){
			$('#flag').val('0');
			$('.promot').hide();
		})
	
	})
	</script>

<%} %>
<div id="body-wrapper">
  <!-- Wrapper for the radial gradient background -->
  <div id="sidebar">
    <div id="sidebar-wrapper">
      <!-- Sidebar with logo and menu -->
      <h1 id="sidebar-title"><a href="#">天成科技CRM管理系统</a></h1>
      <!-- Logo (221px wide) -->
      <a href="#"><img id="logo" src="../../../resources/css/slice/notice.png" alt="logo" /></a>
      <!-- Sidebar Profile links -->
      <div id="profile-links"> <a href="#"><%=EmployeesControl.getEmployeesName(cu.getId())%>,您好！</a> <br />
        <br />
        <a href="#information" rel='modal' >修改个人信息</a> | <a href="../../login/logout.jsp" title="Sign Out">注销</a> </div>
      <ul id="main-nav">
        <!-- Accordion Menu -->
        <li> <a href="#" class="nav-top-item">公司页面 </a>
          <ul>
	          <li><a href='../company/material/material_download.jsp'>资料 </a></li>
	          <li><a href='../company/notice/notice.jsp'>公告</a></li>
	          <li><a href='../company/salearea/salearea.jsp'>销售区域</a></li>
	          <li><a href='../company/saletarget/saletarget.jsp'>销售目标</a></li>
	          <li><a href='../company/show_all_custom_require.jsp'>客户需求登记表</a></li>
          </ul>
         </li>
        <li> <a href="../recepit/show_all_recepits.jsp" class="nav-top-item current no-submenu">
          <!-- Add the class "current" to current menu item -->
           我的跟单</a>
        
        </li>
        <li> <a href="../offer/show_all_offers.jsp" class="nav-top-item no-submenu">报<span class='letter'>价</span></a>      
        </li>
        <li> <a href="../bargain/show_all_bargains.jsp" class="nav-top-item no-submenu">合<span class='letter'>同</span></a>
        </li>
        <li> <a href="../schedule/schedule.jsp" class="nav-top-item no-submenu">日程管理</a></li>
        <li> <a href="../customer/customer.jsp" class="nav-top-item no-submenu">我的客户</a>
        <%
            if(cu.getPosition()!=1){
            	%>
            	<li> <a href="#" class="nav-top-item">统<span class='letter'>计</span></a>
		          <ul>
		            <li><a href="../../control/statistics/company_statistics.jsp">公司统计</a></li>
		            <li><a href="../../control/statistics/employees_statistics.jsp">员工统计</a></li>
		          </ul>
		        </li>
            	<li><a href="../employees/employees.jsp" class="nav-top-item no-submenu">员工管理</a></li>
            	<%
            }
        %>
        </li>
      </ul>
    </div>
  </div>
  <div id="main-content">
  <img src='../../../resources/css/slice/t.png'/>
  <form action="show_all_recepits.jsp?type=1" method="post">
	 <div class="content-box-header">
	 <h3 style="cursor: s-resize;">搜索条件</h3>
	 </div>
	 <table border='1' class='search'>

 		<tr>
 			<td>项目名称</td><td><input type="text" name="title"  value=""/></td>
			 <td>创建人</td><td><input type="text" name="creator"  value="<%if(creator!=null&&!creator.equals("")) out.print(creator); %>"/></td>
			 <td>现跟单人</td><td><input type="text" name="person" value="<%if(person!=null&&!person.equals("")) out .print(person); %>"/></td>
			 <td>客户</td><td><input type="text" name="customer" value="<%if(customer!=null&&!customer.equals("")) out.print(customer); %>"/></td>
			 <td rowspan='2' style='text-align:center; vertical-align:middle;' align='center'><input style='height:40px; width:40px;' class="button" type="submit" value="搜索"/></td>
 		</tr>
	 		<tr class="alt-row">
			<td>分类</td><td><input type="radio" name="sort" value="0" <%if(sort!=null&&sort.equals("0")) out.print("checked"); %>/>一般
				             <input type="radio" name="sort" value="1" <%if(sort!=null&&sort.equals("1")) out.print("checked"); %>/>重要
				             <input type="radio" name="sort" value=""  <%if(sort==null||sort.equals("")) out.print("checked"); %>/>全部</td>
			<td>阶段</td><td><select name="stage" style='width:134px; height:24px;'>
		      <option value="" >请选择</option>
		      <%
		      HashMap stages = GetBaseParam.getAllRecepitStages();
		       Iterator it = stages.entrySet().iterator();
		       while(it.hasNext()){
		    	   Map.Entry entry = (Map.Entry)it.next();
		    	  //System.out.print(""+entry.getKey()+"FF");
		    	   //System.out.print(""+entry.getValue()+"FF");
		    	  %>
		    	  <option value="<%=entry.getKey() %>" <%if(stage!=null&&stage.equals(""+entry.getKey())) out.print("selected"); %>><%=entry.getValue() %></option>
		    	  <%} %>
		    	  </select></td>
		 	<td> 创建时间</td><td> <input style='width:130px;' type="text" name="creat_time"  maxlength="20"  onclick="SelectDate(this,'yyyy-MM-dd')" readonly  style="width:100px;cursor:pointer"/></td>
	 		<td colspan='2'>&nbsp;</td>
	 		</tr>
	 	</table>
 </form>
  <form>
 <fieldset>
 <div class="content-box-header">
<h3 style="cursor: s-resize;">搜索结果</h3>
</div>
 <table>
 <thead>
 <tr>
       <th>跟单项目</th>
        <th>客户名称</th>
        <th>联系人</th>
        <th>创建人</th>
        <th>当前跟单人</th>
        <th>跟单意向</th>
        <th id='stage'>跟单阶段</th>
        <th>跟单分类</th>
        <th id='predictbtn'>预计成交日期</th>
        <th id='money'>预计成交金额</th>
        <th>创建日期</th>
        <th>操作</th>
        </tr>
 </thead>
  <tbody id='tbcontent'>
 <%
              int pages = ParamUtil.getInt(request, "pages", 1);
              int rowsPerPage = ParamUtil.getInt(request, "pageSize", 10);
              int i=0;
              java.util.Date d2 = new java.util.Date();
              Collection recepits = new ArrayList();
              if(userType==1){
                       recepits = RecepitControl.getAllRecepits(title,creator,customer,sort,creat_time,person,stage,String.valueOf(cu.getId()),pages,rowsPerPage);
              }else{
            	       recepits = RecepitControl.getAllRecepits(title,creator,customer,sort,creat_time,person,stage,"",pages,rowsPerPage);
              }
              Iterator it2 = recepits.iterator();
              while(it2.hasNext()){
            	  Recepit r = (Recepit)it2.next();
            	  int id = r.getId();
            	  i++;
 %>
 <tr>
 		<td><input type='hidden' id='time<%=i %>' value="<%out.print(RecepitDescriptionControl.getMaxDescriptionTime(id)); %>"/><%=r.getTitle() %></td>
       <td><%=CustomerControl.getCustomerById(r.getConsumer_id()).getName() %></td>
       <td><%=LinkmanControl.getLinkmanName(r.getLinkman_id()) %></td>
       <td><%=r.getCreator() %></td>
       <td><%=EmployeesControl.getEmpolyeesById(r.getCurrent_person()).getName() %></td>
       <td><%=GetBaseParam.getIntentionById(r.getIntention()) %></td>
       <td><%=GetBaseParam.getStageById(r.getStage()) %><input class='stage' type='hidden' value='<%=r.getStage()%>'/></td>
       <td><%if(r.getSort().equals("1")) out.print("重大"); else out.print("一般");%></td>
       <td class='predicttime'><%=r.getPredict_time() %></td>
       <td><%=r.getPredict_amount() %><input type='hidden' class='money' value='<%=r.getPredict_amount() %>'/></td>
       <td><%=r.getCreat_time() %></td>
	   <td><a href='#message<%=i %>' rel="modal">查看</a><%if(cu.getId()==r.getCurrent_person()){ %>|<a href="../purchase/purchase.jsp?id=<%=r.getId()%>" >采购</a><%}%><%if(cu.getId()==r.getCurrent_person()||cu.getPosition()!=1){ %>|
	   <%}%><%if(cu.getPosition()==100){ %><a href="recepit_delete.jsp?id=<%=r.getId() %>" onClick="return confirm('确认删除？')">删除</a><%} %></td>
</tr>
		  <%
		    
		  }
		  %>
 </tbody>
 </table> 
  <input type='hidden' id='num' value='<%=i %>'/>
		  <%
		  i=0;
		  Iterator it3 = recepits.iterator();
		   while(it3.hasNext()){
            	  Recepit r = (Recepit)it3.next();
            	  i++;
		  %>
		  <div  class='hide' >
	        <div id='message<%=i %>'>
			<iframe id='icheck<%=i %>'style='width:368px; overflow:hidden;' scrolling='no' frameborder='0'  src='recepit_read.jsp?id=<%=r.getId() %>'></iframe>
			</div>
			</div>
		  <%} %>
 <br/>
<%     out.println(RecepitControl.pageInstance.getToolsMenu(pages));
              
 %>
<br/><a class='button' href="#add" rel="modal">添加跟单</a>
<div class='hide' >
	<div id='add'>
		<iframe id='iadd' style='width:368px; overflow:hidden;' scrolling='no' frameborder='0' src='recepit_add.jsp'></iframe>
	</div>
</div>
<div class='hide' >
	<div id='information'>
		<iframe id='iinformation' style='width:368px; overflow:hidden;' scrolling='no' frameborder='0' src='../employees/employees_update.jsp'></iframe>
	</div>
</div>
 </fieldset>
 </form>
</div>
</div>
<div class='promot'>
<input type='hidden' id='flag' value='1'/>
<h4 class='title'>新消息</h4>
<span><img id='close' title="close" src="../../../resources/images/icons/cross.png"></span>
<p class='content'><span class='reply'></span>已转入报价，等待审核。</p>
<span class='check'><a href='../offer/show_all_offers.jsp'>查看</a></span>
</div>
</body>
</html>
